//对于axios进行二次封装
import axios from "axios";
//获取仓库:存储数据
import store from "@/store";
import Promise from 'core-js/fn/promise'
//引入进度条
import nprogress from 'nprogress';
//引入相关进度条的样式
import "nprogress/nprogress.css";


let token = localStorage.getItem("TOKEN");
axios.defaults.headers.common['satoken']= token

//axios.create方法执行,其实返回一个axios和request一样的
let requests = axios.create({
    //基础路径,发请求URL携带api【发现:真实服务器接口都携带/api】
    baseURL: "http://localhost:8080",
    //超时的设置
    timeout: 5000
});

//请求拦截器
requests.interceptors.request.use(config => {
    //进度条开始
    nprogress.start();
    
      return config
});


//响应拦截器
requests.interceptors.response.use((res) => {
    //进度条结束
    nprogress.done();
    return res.data;
}, (err) => {
    alert(err.message);
    //终止Promise链
    return new Promise();
});

export default requests;